﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dm.Domain.Entities;
using Dm.Domain.Repository.RepositoryBase;
using System.Data.Entity;
using Dm.Domain.Repository.Factories;
using Dm.Domain.CrossCutting;

namespace Dm.Domain.Repository.EntityRepositories
{
    public class StudentRepository : RepositoryBase<Student>, IStudentRepository
    {
       
        public List<Student> RetrieveAll(bool includeInactive)
        {
            return base._baseContext.Students.Where(s => 
                (includeInactive ? true : s.StatusId == Settings.Statuses.ActiveStatus)).ToList();
        }

        public List<Student> SearchByName(string firstName, string middleName, string lastName)
        {
            return base._baseContext.Students.Where(c =>
                (c.FirstName.Contains(firstName)) &&
                (c.MiddleName.Contains(middleName)) &&
                (c.LastName.Contains(lastName))).ToList();
        }

        public List<Student> SearchAllParameter(string firstName, string middleName, string lastName, string studentNumber, string email, string contactNumber, string address)
        {
            return base._baseContext.Students.Where(s =>
                ((string.IsNullOrEmpty(firstName)) ? true : s.FirstName.Contains(firstName)) &&
                ((string.IsNullOrEmpty(middleName)) ? true : s.MiddleName.Contains(middleName)) &&
                ((string.IsNullOrEmpty(lastName)) ? true : s.LastName.Contains(lastName)) &&
                ((string.IsNullOrEmpty(studentNumber)) ? true : s.ControlNumber.Contains(studentNumber)) &&
                ((string.IsNullOrEmpty(email)) ? true : s.Email.Contains(email)) &&
                ((string.IsNullOrEmpty(contactNumber)) ? true : s.ContactNumber.Contains(contactNumber)) &&
                ((string.IsNullOrEmpty(address)) ? true : s.Address.AddressLine1.Contains(address))).ToList();
        }

    }
}
